package com.example.javawebproject.util;




import com.example.javawebproject.pojo.Brand;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

public class BrandDB {
    private static Map<Integer, Brand> brands = new LinkedHashMap<Integer, Brand>();
    static {
        brands.put(1, new Brand(1,"小米","小米科技有限公司",1000,"为发烧而生",1));
        brands.put(2, new Brand(2,"三只松鼠","三只松鼠",100,"三只松鼠，好吃不上火",0));
        brands.put(3, new Brand(3,"华为","华为科技有限公司",10,"自强不息",1));
        brands.put(4, new Brand(4,"大疆","大疆科技有限公司",88,"我的天下",1));
        brands.put(5, new Brand(5,"比亚迪","比亚迪汽车有限公司",12,"创建你的梦想",1));
    }

    // 获得所有的图书
    public static Collection<Brand> selectAll() {
        return brands.values();
    }

    // 根据指定的id获得图书
    public static Brand findBrand(Integer id) {
        return brands.get(id);
    }

    public static void add(Brand brand) {
        Integer id =createId();
        brand.setId(id);
        brands.put(id,brand);
    }

    private static Integer createId() {
        Set<Integer> integers = brands.keySet();
        Integer max =0;
        for (Integer id : integers) {
            if (id>max){
                max =id;
            }
        }
        return max+1;
    }
}
